<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>提示信息</title>
    <style>
      .alert {
        width: 50%;
        margin-left: 100px;
        color: #fff;
        padding: 10px;
        position: relative;
        opacity: 1;
        transition: all 1s;
      }
      .test {
        background-color: coral;
      }
      .success {
        background-color: cornflowerblue;
      }
      .info {
        background-color: crimson;
      }
      .warning {
        background-color: darkmagenta;
      }
      .closebtn {
        font-size: 20px;
        position: absolute;
        right: 8px;
        color: #fff;
      }
      .closebtn:hover {
        cursor: pointer;
        color: black;
      }
    </style>
  </head>
  <body>
    <div class="alert test">
      <span class="closebtn">&times;</span>
      <strong>危险!</strong> 危险操作提示。
    </div>

    <div class="alert success">
      <span class="closebtn">&times;</span>
      <strong>成功!</strong> 操作成功提示。
    </div>

    <div class="alert info">
      <span class="closebtn">&times;</span>
      <strong>提示!</strong> 提示信息修改等。
    </div>

    <div class="alert warning">
      <span class="closebtn">&times;</span>
      <strong>警告!</strong> 提示当前操作要注意。
    </div>
    <script>
      let btns = document.getElementsByClassName("closebtn");
      let boxs = document.getElementsByClassName("alert");
      for (let i = 0; i < btns.length; i++) {
        btns[i].onclick = function () {
          boxs[i].style.opacity = "0";
          setTimeout(() => {
            boxs[i].style.display = "none";
          }, 1000);
        };
      }
    </script>
  </body>
</html>
